package com.foreverwin.jzymes.common.service.impl;

import com.foreverwin.jzymes.common.mapper.CustomerMapper;
import com.foreverwin.jzymes.common.service.ICustomerService;
import com.foreverwin.jzymes.common.util.BOHandleUtil;
import com.foreverwin.jzymes.framework.util.I18nUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Map;
@Service
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    CustomerMapper customerMapper;

    /**
     * 检查客户是否存在
     *
     * @param site
     * @param customer
     * @return
     */
    @Override
    public Map<String, Object> existCustomer(String site,String customer) {
        Assert.hasText( site, I18nUtil.getI18nText( "common.siteNotBlank" ) );
        Assert.hasText( customer, I18nUtil.getI18nText( "common.customerNotBlank" ) );
        String handle = BOHandleUtil.buildCustomerHandle( site,customer );
        Map<String,Object> customerMap = customerMapper.selectCustomerMap(handle);
        Assert.notNull(customerMap,I18nUtil.getI18nText("common.customerNotExsited",new String[]{ customer }));

        return customerMap;
    }
    /**
     * 检查用户是否存在
     *
     * @param site
     * @param user
     * @return
     */
    @Override
    public Map<String, Object> existUser(String site, String user) {
        Assert.hasText( site, I18nUtil.getI18nText( "common.siteNotBlank" ) );
        Assert.hasText( user , I18nUtil.getI18nText( "common.userNotBlank" ) );
        Map<String,Object> userMap = customerMapper.selectUserMap( site , user );
        Assert.notNull( userMap , I18nUtil.getI18nText("common.userNotExist",new String[] { user }) );

        return userMap;
    }
}
